/*以二进制形式打印整数*/
#include<stdio.h>

void to_binary(unsigned long n);

int main(void)
{
    unsigned long num;      //%lu

    printf("Enter an integer (q to quit):");
    while(scanf("%lu", &num) == 1)
    {
        printf("Binary equivalent:");
        to_binary(num);
        putchar('\n');
        printf("Enter an integer (q to quit):");
    }
    printf("Done!");

    return 0;
}

void to_binary(unsigned long n) //递归 循环 两者不包含
{
    unsigned long r;

    r = n % 2;
    if(n >= 2)      //while  陷入死循环
    {
        to_binary(n / 2);
    }
    putchar(r == 0 ? '0' : '1');

    return;
}